<!--
 * @Descripttion: 监管-财政拨款-列表
 * @version:
 * @Author: zhangfan
 * @email: 2207044692@qq.com
 * @Date: 2020-06-03 14:02:12
 * @LastEditors: younghxp
 * @LastEditTime: 2022-03-30 15:22:05
-->
<template>
  <div class="container" ref="mainCon">
    <topTitle :titleText="titleText"></topTitle>
    <div class="mainCon">
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <el-col :lg="8" :xl="6">
            <el-form-item label="区域" class="row-padding-bottom">
              <el-cascader
                ref="manageArea"
                v-model="areaId"
                :options="areasOptions"
                @change="getAreaId"
                height="250"
                clearable
                filterable
                :props="{ checkStrictly: true }"
              ></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="项目名称" class="row-padding-bottom">
              <el-input
                v-model="filterField.projectName"
                placeholder="请输入项目名称"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="行业" class="row-padding-bottom">
                <el-select
                  v-model="filterField.industryId"
                  filterable
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="item in industryOptions"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="状态" class="row-padding-bottom">
                <el-select
                  v-model="filterField.status"
                  filterable
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="item in statusOptions"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item>
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchList"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
            <el-form-item>
              <exportBtn
                :dataLen="tableList.length"
                :filterField="filterField"
                api="api-s/report/export_CZBM_FINANCIAL"
              ></exportBtn>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableList"
          v-loading="loading"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          @sort-change="sortChange"
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column prop="projectName" label="项目名称" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.projectName"
                :columnName="'projectName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="areaDetailDesc"
            label="区域"
            :formatter="formatTd"
            width="150"
          >
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.areaDetailDesc"
                :columnName="'areaDetailDesc'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="industryName"
            label="行业"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="pcName"
            label="建设方"
            :formatter="formatTd"
            width="230"
          >
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.pcName"
                :columnName="'pcName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="pbName"
            label="施工方"
            :formatter="formatTd"
            width="230"
          >
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.pbName"
                :columnName="'pbName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="total"
            label="工程造价(万元)"
            align="center"
            :formatter="dateForma"
            sortable="custom"
            width="150"
          ></el-table-column>
          <el-table-column
            prop="statusDesc"
            label="状态"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="investmentDesc"
            label="投资类型"
            align="center"
            :formatter="formatTd"
            width="110"
          ></el-table-column>
          <el-table-column
            prop="grantAll"
            label="财政拨款(万元)"
            align="center"
            :formatter="dateForma"
            sortable="custom"
            width="150"
          ></el-table-column>
          <el-table-column label="操作" align="left" fixed="right" width="110">
            <template slot-scope="scope">
              <el-link
                type="primary"
                v-if="isShowDetail"
                @click="toFinancialBtn(scope.row)"
                >财政拨款</el-link
              >
              <span v-else>--</span>
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <!-- getTableList为获取子组件的数据 -->
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
        ></Pagination>
      </div>
      <!-- 财政拨款弹框展示 -->
      <el-dialog
        title="财政拨款"
        :visible.sync="accountFormVisible"
        :close-on-click-modal="false"
        custom-class="brand-dialog-min-width"
        class="financialVisible"
        width="640px"
        :modal-append-to-body="false"
      >
        <el-table
          :data="tableListCZ"
          v-loading="loadingCZ"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          style="border: 1px solid #dfe6ec"
          :default-sort="{ prop: 'date', order: 'descending' }"
        >
          <el-table-column
            prop="grantDate"
            label="拨款时间"
            align="center"
            :formatter="formatTd"
            width="160px"
          ></el-table-column>
          <el-table-column
            prop="amount"
            label="拨款金额(元)"
            align="center"
            width="140px"
            :formatter="dateFormaJgCZ"
          ></el-table-column>
          <el-table-column
            prop="remark"
            label="备注"
            align="left"
            :formatter="formatTd"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <PaginationCZ
          ref="paginationCZ"
          @getList="getTableListCZ"
          :requestUrl="requestUrlCZ"
          :projectId="projectIdCZ"
        ></PaginationCZ>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import PaginationCZ from '@/components/publicCom/paginationCZ'
import scrollTable from '@/mixin/scrollTable.js'
import { mapState, mapActions } from 'vuex'
export default {
  name: 'projectListJgCZ',
  mixins: [scrollTable],
  components: {
    PaginationCZ,
  },
  data() {
    return {
      advanced: false,
      accountFormVisible: false, //是否显示财政拨款弹框
      advanced: false,
      textarea: '',
      bankOptions: [],
      projectIdCZ: '',
      canLogin: false, //专户保存按钮loading
      formRules: {
        time: [
          {
            required: true,
            message: '拨款时间不能为空',
            trigger: 'change',
          },
        ],
        account: [
          {
            required: true,
            message: '拨款金额不能为空',
            trigger: 'change',
          },
        ],
      },
      titleText: '财政拨款',
      //财政-财政拨款-列表表格数据
      tableList: [],
      //财政-财政拨款-财政拨款表格数据
      tableListCZ: [],
      requestUrl: 'api-p/project/expand/findGrantProject',
      requestUrlCZ: 'api-p/projectgrantdetail/base/grantDetaillist',
      areaId: '', //区域
      //搜索条件
      filterField: {
        projectName: '', //项目名称
        areaId: '', //区域
        status: '', //开工状态
        industryId: '', //行业
        investment: 'GOV', //投资类型
        serverArea: '', // 服务部署区域
      },
      bankData: [],
      isShow: false, //列表加载
      loading: true,
      loadingCZ: true,
      isShowDetail: '',
    }
  },
  watch: {
    accountFormVisible: {
      handler(oldVal, newVal) {
        if (newVal === false) {
          this.$nextTick(function () {
            this.$refs.paginationCZ.getTableListDataCZ()
          })
        }
      },
      deep: true,
      immediate: true,
    },
  },
  computed: {
    ...mapState([
      'investmentOptions',
      'statusOptions',
      'areasOptions',
      'industryOptions',
    ]),
  },
  created() {
    this.getInvestmenttype({})
    this.getStatus({})
    this.getAreas({ areaId: this.$store.state.areaInfoArr.areaId })
    this.getIndustry({})
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
    this.filterField.serverArea = this.$store.state.areaInfoArr.areaId
    this.isShowDetail =
      this.$store.state.buttonLimitsArr.indexOf('mProjectList:detail') > -1 ||
      this.$store.state.buttonLimitsArr.indexOf('projectList:detail') > -1 ||
      this.$store.state.buttonLimitsArr.indexOf('projectListJgCZ:detail') > -1
  },
  methods: {
    ...mapActions([
      'getInvestmenttype',
      'getStatus',
      'getAreas',
      'getIndustry',
    ]),
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    reviseFinancialBtn() {
      this.reviseFinancialForm.remarks = ''
      this.reviseFinancialVisible = true
    },
    //获取选中的区域最后一级id
    getAreaId() {
      var areaId = this.areaId[this.areaId.length - 1]
      this.filterField.areaId = areaId
    },
    //获取财政-财政拨款-列表表格数据
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },
    //获取财政-财政拨款-财政拨款表格数据
    getTableListCZ(data) {
      this.tableListCZ = data
      this.loadingCZ = false
      if (this.tableListCZ.length < 1) {
        this.isShow = true
      }
    },
    // 搜索
    searchList() {
      this.$refs.pagination.getTableListData()
    },
    //财政拨款弹框
    toFinancialBtn(row) {
      this.projectIdCZ = row.id
      this.accountFormVisible = true
    },
    dateFormaJgCZ(row, column) {
      const daterc = row[column.property]
      if (daterc || daterc == 0) {
        return this.toFixed(daterc, 2)
      } else {
        return '--'
      }
    },
    dateForma(row, column) {
      const daterc = row[column.property]
      if (daterc || daterc == 0) {
        let lately2 = daterc / 10000
        return this.toFixed(lately2, 2)
      } else {
        return '--'
      }
    },
  },
}
</script>

<style scoped lang="less">
.financialVisible {
  .addFinancial {
    margin-bottom: 12px;
    float: right;
  }
}

/deep/ .el-input-number .el-input__inner {
  text-align: left;
}
.container {
  flex-grow: 1;
  .mainCon {
    top: 198px;
    flex-grow: 1;
    flex-shrink: 1;
  }
}
@import '../../../static/css/filterArea.less';
</style>
